package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReEvaluate;
import com.ruoyi.system.service.IReEvaluateService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中介奖惩记录Controller
 * 
 * @author ruoyi
 * @date 2023-12-23
 */
@Controller
@RequestMapping("/system/evaluate")
public class ReEvaluateController extends BaseController
{
    private String prefix = "system/evaluate";

    @Autowired
    private IReEvaluateService reEvaluateService;


    @Autowired
    private ISysUserService userService;

    @RequiresPermissions("system:evaluate:view")
    @GetMapping()
    public String evaluate()
    {
        return prefix + "/evaluate";
    }


    @GetMapping("/selectMyUser")
    public String selectMyUser()
    {
        return prefix + "/selectUser";
    }
    /**
     * 查询中介奖惩记录列表
     */
    @RequiresPermissions("system:evaluate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReEvaluate reEvaluate)
    {
        startPage();
        List<ReEvaluate> list = reEvaluateService.selectReEvaluateList(reEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出中介奖惩记录列表
     */
    @RequiresPermissions("system:evaluate:export")
    @Log(title = "中介奖惩记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReEvaluate reEvaluate)
    {
        List<ReEvaluate> list = reEvaluateService.selectReEvaluateList(reEvaluate);
        ExcelUtil<ReEvaluate> util = new ExcelUtil<ReEvaluate>(ReEvaluate.class);
        return util.exportExcel(list, "中介奖惩记录数据");
    }

    /**
     * 新增中介奖惩记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存中介奖惩记录
     */
    @RequiresPermissions("system:evaluate:add")
    @Log(title = "中介奖惩记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReEvaluate reEvaluate)
    {
        return toAjax(reEvaluateService.insertReEvaluate(reEvaluate));
    }

    /**
     * 修改中介奖惩记录
     */
    @RequiresPermissions("system:evaluate:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReEvaluate reEvaluate = reEvaluateService.selectReEvaluateById(id);
        mmap.put("reEvaluate", reEvaluate);
        return prefix + "/edit";
    }

    /**
     * 修改保存中介奖惩记录
     */
    @RequiresPermissions("system:evaluate:edit")
    @Log(title = "中介奖惩记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReEvaluate reEvaluate)
    {
        return toAjax(reEvaluateService.updateReEvaluate(reEvaluate));
    }

    /**
     * 删除中介奖惩记录
     */
    @RequiresPermissions("system:evaluate:remove")
    @Log(title = "中介奖惩记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reEvaluateService.deleteReEvaluateByIds(ids));
    }

    /**
     * 查询中介户角色列表
     */
    @RequiresPermissions("system:evaluate:list")
    @PostMapping("/unallocatedList")
    @ResponseBody
    public TableDataInfo unallocatedList(SysUser user)
    {
        if(user==null){
            user=new SysUser();
        }
        user.setPost("1");
        startPage();
        List<SysUser> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    /**
     * 状态修改
     */
    @Log(title = "奖惩记录--是否启用", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:evaluate:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(ReEvaluate reEvaluate)
    {

        return toAjax(reEvaluateService.updateReEvaluate(reEvaluate));
    }
}
